package com.muyu.danmo.controller;


import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.danmo.service.IDanmoOrderItemService;
import com.muyu.system.domain.DanmoOrderItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 订单项信息Controller
 * 
 * @author yangle
 * @date 2025-01-23
 */
@RestController
@RequestMapping("/orderItem")
public class DanmoOrderItemController extends BaseController
{
    @Autowired
    private IDanmoOrderItemService danmoOrderItemService;

    /**
     * 查询订单项信息列表
     */
//    @RequiresPermissions("system:orderItem:list")
    @GetMapping("/list")
    public Result list(DanmoOrderItem danmoOrderItem)
    {
        startPage();
        List<DanmoOrderItem> list = danmoOrderItemService.selectDanmoOrderItemList(danmoOrderItem);
        return getDataTable(list);
    }

    /**
     * 导出订单项信息列表
     */
//    @RequiresPermissions("system:orderItem:export")
    @Log(title = "订单项信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DanmoOrderItem danmoOrderItem)
    {
        List<DanmoOrderItem> list = danmoOrderItemService.selectDanmoOrderItemList(danmoOrderItem);
        ExcelUtil<DanmoOrderItem> util = new ExcelUtil<DanmoOrderItem>(DanmoOrderItem.class);
        util.exportExcel(response, list, "订单项信息数据");
    }

    /**
     * 获取订单项信息详细信息
     */
//    @RequiresPermissions("system:orderItem:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id)
    {
        return Result.success(danmoOrderItemService.selectDanmoOrderItemById(id));
    }

    /**
     * 新增订单项信息
     */
//    @RequiresPermissions("system:orderItem:add")
    @Log(title = "订单项信息", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody DanmoOrderItem danmoOrderItem)
    {
        return danmoOrderItemService.insertDanmoOrderItem(danmoOrderItem);
    }

    /**
     * 修改订单项信息
     */
//    @RequiresPermissions("system:orderItem:edit")
    @Log(title = "订单项信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody DanmoOrderItem danmoOrderItem)
    {
        return danmoOrderItemService.updateDanmoOrderItem(danmoOrderItem);
    }

    /**
     * 删除订单项信息
     */
//    @RequiresPermissions("system:orderItem:remove")
    @Log(title = "订单项信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids)
    {
        return danmoOrderItemService.deleteDanmoOrderItemByIds(ids);
    }
}
